import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yp/config/style.dart';
import 'package:yp/widgets/bottom_sheet.dart';
import 'package:yp/widgets/button_widget.dart';
import 'package:yp/widgets/cache_image.dart';
import 'package:yp/widgets/navigation_bar.dart';

/// 我的分享
class MyShare extends StatefulWidget {
  const MyShare({Key key}) : super(key: key);

  @override
  _MyShareState createState() => _MyShareState();
}

class _MyShareState extends State<MyShare> with SingleTickerProviderStateMixin {
  RefreshController _refreshController =
      RefreshController(initialRefresh: true);

  List<String> _infoList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    _refreshController.dispose();
  }

  void _onLoading() async {
    await Future.delayed(Duration(milliseconds: 1000), () {
      _infoList.addAll(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
    }).whenComplete(() {
      if (mounted) {
        _refreshController.loadComplete();
      }
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: YPNavigationBar('我的分享'),
      body: SmartRefresher(
        enablePullDown: false,
        enablePullUp: true,
        footer: ClassicFooter(),
        controller: _refreshController,
        onLoading: _onLoading,
        child: CustomScrollView(
          physics: BouncingScrollPhysics(),
          slivers: [
            SliverToBoxAdapter(
              child: Column(
                children: [
                  Container(
                    padding: const EdgeInsets.fromLTRB(12, 20, 12, 10),
                    color: EsColors.White,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '张三' + '  ' + '分享所得奖励',
                          style: TextStyle(
                              color: EsColors.TitleSecondary,
                              fontSize: EsSizes.MD,
                              fontWeight: EsFontWeights.Normal),
                        ),
                        Padding(
                          padding: const EdgeInsets.symmetric(vertical: 20),
                          child: Row(
                            children: [
                              Expanded(
                                  child: Row(
                                children: [
                                  Image(
                                      image: AssetImage(
                                          'assets/images/integral.png')),
                                  SizedBox(width: 8),
                                  RichText(
                                      text: TextSpan(children: [
                                    TextSpan(
                                        text: '积分' + '  ',
                                        style: TextStyle(
                                            color: EsColors.TitleSecondary,
                                            fontSize: EsSizes.SM,
                                            fontWeight: EsFontWeights.Normal)),
                                    TextSpan(
                                        text: '+455',
                                        style: TextStyle(
                                            color: EsColors.ContentSecondary,
                                            fontSize: EsSizes.SM,
                                            fontWeight: EsFontWeights.Normal))
                                  ]))
                                ],
                              )),
                              Expanded(
                                  child: Row(
                                children: [
                                  Image(
                                      image: AssetImage(
                                          'assets/images/coupon_tips.png')),
                                  SizedBox(width: 8),
                                  RichText(
                                      text: TextSpan(children: [
                                    TextSpan(
                                        text: '优惠券' + '  ',
                                        style: TextStyle(
                                            color: EsColors.TitleSecondary,
                                            fontSize: EsSizes.SM,
                                            fontWeight: EsFontWeights.Normal)),
                                    TextSpan(
                                        text: '+4张',
                                        style: TextStyle(
                                            color: EsColors.ContentSecondary,
                                            fontSize: EsSizes.SM,
                                            fontWeight: EsFontWeights.Normal))
                                  ]))
                                ],
                              ))
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  SizedBox(height: 15),
                ],
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate((ctx, index) {
                return _orderItem();
              }, childCount: _infoList.length),
            ),
          ],
        ),
      ),
    );
  }

  /// 订单item
  Widget _orderItem() {
    return GestureDetector(
      onTap: () {
        /// 查看商品详情
      },
      child: Container(
        margin: const EdgeInsets.fromLTRB(12, 0, 12, 10),
        padding: const EdgeInsets.all(10),
        decoration: EsDecoration.BoxShadowWithRadius,
        child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
          CachedImage(
              width: 80,
              height: 80,
              margin: EdgeInsets.fromLTRB(0, 10, 8, 12),
              scale: BoxFit.cover,
              path:
                  'http://imgservice.suning.cn/uimg1/b2c/image/LbK15Wx6ONCA2R1lpJXkOg.jpg_800w_800h_4e'),
          SizedBox(width: 6),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  'Nature Republic自然共和国院子然可原芦荟胶补水面膜面膜',
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      color: EsColors.TitleSecondary,
                      fontSize: EsSizes.SM,
                      fontWeight: EsFontWeights.Normal),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 2, bottom: 3),
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                        text: '￥',
                        style: TextStyle(
                            fontSize: EsSizes.XXS,
                            color: EsColors.Primary,
                            fontWeight: EsFontWeights.Medium)),
                    TextSpan(
                        text: '29489.00' + ' ',
                        style: TextStyle(
                            fontSize: EsSizes.MD,
                            color: EsColors.Primary,
                            fontWeight: EsFontWeights.SemiBold)),
                    TextSpan(
                        text: '2289.00',
                        style: TextStyle(
                            fontSize: EsSizes.SM,
                            decoration: TextDecoration.lineThrough,
                            color: EsColors.ContentSecondary,
                            fontWeight: EsFontWeights.Normal)),
                  ])),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 2, bottom: 10),
                  child: Text(
                    '截止2020.02.12 00:00:00',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        color: EsColors.ContentSecondary,
                        fontSize: EsSizes.XS,
                        fontWeight: EsFontWeights.Normal),
                  ),
                ),
                SizedBox(height: 10),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    EsOutLineButton(
                      '去分享',
                      padding:
                          EdgeInsets.symmetric(vertical: 3, horizontal: 19),
                      onTap: () {
                        print('去分享');
                        YpBottomSheet.showShareGift(context,
                            (selectIndex, selectString, {info}) {
                          print(selectIndex.toString() + selectString);
                        });
                      },
                    )
                  ],
                )
              ],
            ),
          ),
        ]),
      ),
    );
  }
}
